﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Delay;

namespace PhoneInfo.Page
{
    public partial class MessageBoard : PhoneApplicationPage
    {
        ReplyResult replyResult=null;
        public bool intoChange = true;
        public MessageBoard()
        {
            InitializeComponent();
            ApplicationBar = ((ApplicationBar)this.Resources["AppBar"]);
            ReplyContent.Focus();
            Loaded += new RoutedEventHandler(MessageBoard_Loaded);
        }

        void MessageBoard_Loaded(object sender, RoutedEventArgs e)
        {
            if (App.appSitting.Theme == 1)
                ApplicationBar = (ApplicationBar)this.Resources["AppBar"];
            else
                ApplicationBar = (ApplicationBar)this.Resources["AppBar1"];
            ReplyContent.Focus();
        }
        private void Reply(object sender, EventArgs e)
        {
            string content = ReplyContent.Text;
            if (content.Length == 0)
            {
                MessageBox.Show("评论的内容不能为空");
                return;
            }
            if (replyResult == null)
            {
                replyResult = new ReplyResult();
                replyResult.Result = -1;
                replyResult.ResultMsg = "";
                replyResult.IsLogo = -1;
                replyResult.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(replyResult_PropertyChanged);
                replyResult.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(replyResult.GetPhoneInfoUrl(content,"1.0")));
                //此时才发表评论
                FullModePopup.IsOpen = true;
                rezultMsg.Visibility = Visibility.Collapsed;
                ProgBar.Visibility = Visibility.Visible;
                btnsubmit.Focus();
                ApplicationBar = null;
            }
        }
        void replyResult_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            //throw new NotImplementedException();
            if (sender == null)
            {
                return;
            }
            ReplyResult se = (ReplyResult)sender;
            if (e.PropertyName == "Result")
            {
                //进行处理
                if (se.Result == 0)
                {
                    rezultMsg.Text = se.ResultMsg;
                    rezultMsg.Visibility = Visibility.Visible;
                    ProgBar.Visibility = Visibility.Collapsed;
                    ApplicationBar = ((ApplicationBar)this.Resources["AppBar"]);
                }
                else if (se.Result == 1 || se.Result == 2)
                {//success
                    rezultMsg.Text = se.ResultMsg;
                    rezultMsg.Visibility = Visibility.Visible;
                    ProgBar.Visibility = Visibility.Collapsed;
                    ApplicationBar = ((ApplicationBar)this.Resources["AppBar"]);
                    FullModePopup.IsOpen = false;
                    MessageBox.Show("已留言！");
                    NavigationService.GoBack();
                }
            }
        }
    }
}